<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>接待反馈</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form :model="editForm" label-width="100px" ref="editForm">
          <el-form-item label="入学意向：">
            <el-radio-group v-model="editForm.status">
              <el-radio label="3">立即报名</el-radio>
              <el-radio label="2">待考虑</el-radio>
              <el-radio label="1">不报名</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="带看反馈：" prop="name">
            <el-input
              v-model="editForm.remark"
              auto-complete="off"
              placeholder="填写接待反馈（可不填）"
              type="textarea"
              :rows="2"
            ></el-input>
          </el-form-item>
          <el-form-item label="带看图片：" prop="name">
            <el-upload
              :action="$uploadImg"
              list-type="picture-card"
              :file-list="fileList"
              :limit="100"
              accept=".jpg,.jpeg,.png"
              multiple
              :on-success="handleSuccessImg"
              :on-remove="handleRemove">
              <i class="el-icon-plus"></i>
            </el-upload>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">返回</el-button>
        <el-button size="small" type="primary" @click.native="editSubmit">确定并保存</el-button>
      </div>
    </div>
    <AuxiliaryModule @getInformation="getInformation" typeData="recruit_add"></AuxiliaryModule>
  </div>
</template>

<script>
import {recuitDistribution} from '@/api/admin/recuit'

export default {
  props: ['visible', 'recruitId'],
  components: {},
  data() {
    return {
      dialogVisible: false,
      editForm: {
        id: '', // 	字符串 	必填 	1 	- 	ID
        pic: '', // 	字符串 	必填 	1 	- 	照片
        status: '3', // 	字符串 	必填 	1 	- 	0待接待1不入学2待考虑3计划入学
        remark: '', // 	字符串 	必填 	1 	- 	备注
      }, // 编辑界面数据
      // 限制时间选择
      userType: 0, // 1 招待 2 审核
      uploadPic: [],
      fileList: []
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (!this.visible) {
        this.editForm = {
          pic: '', // 	字符串 	必填 	1 	- 	照片
          status: '3', // 	字符串 	必填 	1 	- 	0待接待1不入学2待考虑3计划入学
          remark: '', // 	字符串 	必填 	1 	- 	备注
        }
        this.uploadPic = []
        this.fileList = []
      }
    }
  },
  created() {
  },
  methods: {
    handleRemove(file, fileList) {
      console.log(file);
      console.log(this.uploadPic);
      for (let i in this.uploadPic) {
        if (this.uploadPic[i].uploadPic === file.uploadPic) {
          this.uploadPic.splice(i, 1)
          return
        }
      }
    },
    handleSuccessImg(response) {
      console.log('res', response)
      this.uploadPic.push({
        url: response.data.name,
        uploadPic: response.data.name
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 提交数据
    async editSubmit() {
      console.log('this.uploadPic:', this.uploadPic, this.fileList)
      let dataOption = this.getJson(this.editForm)
      if (!this.uploadPic.length) {
        this.$message.error('至少上传一张招待图')
        return
      }
      let pic_ = []
      for (let item of this.uploadPic) {
        pic_.push(item.uploadPic)
      }
      dataOption.pic = pic_.join(',')
      dataOption.id = this.recruitId
      recuitDistribution(dataOption).then(res => {
        if (!res.code) {
          this.$message.success('编辑成功！')
          this.$emit('InitFn')
          this.closePOpup()
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    getInformation(option) {
      console.log('option:', option)
      let uploadPic_ = []
      for (let item of this.uploadPic) {
        uploadPic_.push(item.url)
      }
      let status = false
      console.log('uploadPic_', uploadPic_)
      for (let item of option) {
        // if (item.type === 'img' && item.number === 1) {
        //   this.foodEdit.pic = item.value[0].url
        // }
        if (item.type === 'img' && item.number !== 1) {
          for (let item_list of item.value) {
            if(uploadPic_.indexOf(item_list.url)==-1){
              item_list.uploadPic = item_list.url
              this.uploadPic.push(item_list)
              status =true
            }
          }
          // this.fileList = JSON.parse(JSON.stringify(this.uploadPic))
        }
      }
      console.log('status', status)
      if(status){
        this.fileList = JSON.parse(JSON.stringify(this.uploadPic))
      }
      // let list = JSON.parse(JSON.stringify(this.fileList))
      // for (let item of list) {
      //   item.src = item.response ? item.response.data.pic : item.url
      // }
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 50%;
  height: 80%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.hearder-search {
  display: flex;
  align-items: center;
}
</style>


